package net.wanho.task;

import net.wanho.server.WebSocketServer;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Author：汤小洋
 * Date：2024-01-17 17:14
 * Description：<描述>
 */
@Component
public class WebSocketTask {

    @Resource
    private WebSocketServer webSocketServer;

    @Scheduled(cron = "0/5 * * * * ?")
    public void sendMessage(){
        webSocketServer.sendToAllClient("这是服务器定时发送的消息: " + DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now()));
    }
}
